<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
/*   
    body {
      background: #000000;
    } */
  
    .list-card {
      width: 900px;
      background: #ffffff;
      border-radius: 10px;
      margin: 20px 0;
      padding: 20px;
    }
  
    .table-layout {
      width: 100%;
      table-layout: fixed;
      border-collapse: collapse;
    }
  
    .table-cell {
      display: table-cell;
      text-align: center;
      height: 60px;
      border: 1px solid #e4e4e4;
      color: #333333;
      font-size: 14px;
    }
  
    @page {
      /* size: auto; */
      margin: 20px 20px 0;
    }
  </style>
</head>
<body>
  <button onclick="print()">打印</button>
  <div class="list-card">
    <div class="table-container">
      <div class="table-container">
        <table class="table-layout">
          <tbody>
            <tr>
              <td class="table-cell">
                左青龙
              </td>
              <td class="table-cell" colspan="6">
                右白虎
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</body>
</html>
<script>
  // const print = () => {
  //   const newDom = document.querySelector(".list-card").innerHTML;
  //   const oldDom = document.body.innerHTML;
  //   document.body.innerHTML = newDom;
  //   window.print();
  //   document.body.innerHTML = oldDom;
  //   window.location.reload();
  // }

const print = () => {
  const dom = document.querySelector(".list-card").outerHTML;
  const iframe = document.createElement("iframe");
  iframe.setAttribute("style", "position:absolute;width:0;height:0;top:-10px;left:-10px;");
  document.body.appendChild(iframe);

  const iframeDom = iframe.contentDocument;

  let str = ''
  const styles = document.querySelectorAll("style,link").forEach(item => {
    str += item.outerHTML;
  });

  iframeDom.open();
  iframeDom.write(str + dom);
  iframeDom.close();

  iframe.contentWindow.print();
  document.body.removeChild(iframe);
}

</script>